<template>
	<view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			};
		},
		onLoad() {
			const page = uni.getStorageSync('page')
			const fromPage = uni.getStorageSync('fromPage')
			// if(page=='guide'){
			// 	uni.switchTab({
			// 	 url:'/pages/home/home'
			// 	})
			// }else{
			// uni.redirectTo({
			// 	url: '/pages/guide/guide'
			// });
			// }
			if (page == 'guide' || page === 'Qa'&& fromPage !== 'culture' || page === 'order-list') {
				uni.switchTab({
					url: '/pages/home/home'
				});
			} else if (page === 'Qa' && fromPage === 'culture') {
				uni.switchTab({
					url: '/pages/culture/culture'
				});
			} else {
				uni.redirectTo({
					url: '/pages/guide/guide'
				})
			}

			// 获取openid
			this.ifRegisted()

		},
		onUnload() {

		},
		methods: {
			// 获取opeind
			async getOpenId(code) {
				const {
					data: res
				} = await uni.$http.post('/user/getModelByCode', {
					code: code
				})
				console.log(res)
				if (res.success == 0) {
					this.openId = res.data.openid
					uni.setStorageSync('openId', res.data.openid)
					this.session_key = res.data.session_key
				}
			},
			ifRegisted() {
				var that = this
				uni.login({
					provider: 'weixin',
					success: res => {
						var that = this
						that.getOpenId(res.code)
						uni.setStorageSync('setcode', res.code)
					},
					fail: res => {
						console.log(res)
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
